import { PrismaService } from '@/common/service/prisma/prisma.service';
import { Injectable } from '@nestjs/common';

@Injectable()
export class WordService {

    constructor(private prisma: PrismaService) { }

    async GetWords(name: string) {

        const resp = await this.prisma.$queryRawUnsafe(`select * FROM ${name}; `)

        return resp
    }

    async GetOptions() {
        const resp:any[] = await this.prisma.$queryRawUnsafe(`
            SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE();
            `)
        const result = resp.map(e=>e.TABLE_NAME)
        const filter:string[]=[]
        const sys:string[]=[
            'front_account', 'gen_table', 'gen_table_column', 'sys_config', 'sys_dept', 'sys_dict_data', 'sys_dict_type', 'sys_logininfor', 'sys_menu', 'sys_notice', 'sys_post', 'sys_role', 'sys_role_dept', 'sys_role_menu', 'sys_user', 'sys_user_post', 'sys_user_role',
        ]
        result.forEach(element => {
             if(!sys.includes(element)){
                 filter.push(element)
             }
        });
        return filter
    }
}
